package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.QuestionDao;
import ysq.xyg.model.Question;
import ysq.xyg.service.QuestionService;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author yu sheng qiang
 * @create 2017-03-22 15:36
 **/
@Service("questionService")
public class QuestionServiceImpl extends BaseServiceImpl<Question> implements QuestionService {


    @Resource
    private QuestionDao questionDao;
    @Autowired
    public void setQuestionDao(QuestionDao questionDao) {
        this.baseDao = questionDao;
    }

    @Override
    public PageInfo<Question> pageInfo(Question question, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        // 通用Example查询
        Example example = new Example(Question.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(question.getName())) {
            criteria.andLike("name", "%" + question.getName() + "%");
        }

        List<Question> list = questionDao.selectByExample(example);
        return new PageInfo<Question>(list);
    }
    @Override
    public List<Question> list(Question question) {
        // 通用Example查询
        Example example = new Example(Question.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(question.getName())) {
            criteria.andLike("name", "%" + question.getName() + "%");
        }

        example.setOrderByClause(" level_num asc ");
        List<Question> list = questionDao.selectByExample(example);
        return list;
    }
}
